function GameEngine(canvasId,playerPanelId){
	var canvas = document.getElementById(canvasId);
	var canvasContext = canvas.getContext('2d');
	this.canvasContext = canvasContext;
	
	var playerPanelCanvas = document.getElementById(playerPanelId).getContext('2d');
	
	var player = null;	
	var playerPanel = null;
	var gameObjects = [];	
	
	var collisionSolver = new CollisionSolver(canvas.width,canvas.height);	
	this.imageManager = null;
	
	this.addObject = function(obj){		
		obj.gameEngine = this;
		gameObjects.push(obj);
	};		
		
	this.run = function(){	
		this.initGame();		
		setInterval(this.gameLoop,30);
	};	
	update = function(){		
		for(var i=0;i<gameObjects.length;++i){
			gameObjects[i].update();
			collisionSolver.resolveEdgesCollision(gameObjects[i].parent);
		}
		for(var i=0;i<gameObjects.length;++i){
			for(var j=i+1;j<gameObjects.length;++j){
				if(collisionSolver.checkCollision(gameObjects[i].parent,gameObjects[j].parent)){
					collisionSolver.solveCollision(gameObjects[i],gameObjects[j]);	
				};
			}
		}	
		var tmpObjects = [];
		for(var i=0;i<gameObjects.length;++i){
			if(!gameObjects[i].parent.toRemove){
				tmpObjects.push(gameObjects[i]);
			}
		}
		gameObjects = tmpObjects;
		
	}
	draw = function(){	
		var ctx = canvasContext;	
		ctx.strokeStyle = "black";
		ctx.clearRect(0,0,canvas.width,canvas.height);
		ctx.strokeRect(0,0,canvas.width,canvas.height);
		for(var i=0;i<gameObjects.length;++i){
			ctx.save();
			gameObjects[i].draw(ctx);
			ctx.restore();
		} 
		playerPanel.draw();
	};	
	this.gameLoop = function(game){
		this.update();
		this.draw();
	};
	this.initGame = function(){
		player = new Rocket();
		player.parent.x=canvas.width/2;
		player.parent.y=canvas.height/2;		
		this.addObject(player);	
		
		playerPanel = new PlayerPanel(playerPanelCanvas,player);
		
		canvas.onmousemove = function(event){
			var bb = canvas.getBoundingClientRect();
			player.parent.targetX = event.clientX - bb.left;
			player.parent.targetY = event.clientY - bb.top;									
		};	
	}
}
